MIDI Scores

by Hubert Howe

I have developed a MIDI score format that allows composers to create note lists representing musical specifications, and a program called SCO2MIDI which translates them into a standard MIDI file. In addition, I have also created a MIDI2SCO utility that allows standard MIDI files to be decoded into this score format. (These programs exist only for the IBM PC family of computers.) The score format is similar to that used for standard numeric scores by computer music synthesis programs like csound. The score file can be prepared and edited with any word processor capable of producing ASCII text files.

All types of MIDI events can be represented, but the format is most suitable for notes (which include both note on and off messages) and controller messages. Large numbers of MIDI messages would be necessary to simulate the manner in which standard MIDI devices operate after touch and pitch bender messages. One of the main features of the SCO2MIDI and MIDI2SCO programs is that they allow inspection of MIDI file data in a completely accurate numeric format, showing exactly how expressive data and quantizing "errors" exist in a sequence. Once translated into a standard MIDI file, the data can be converted to notation by programs such as Finale, or edited with sequencer programs such as Master Tracks or Cakewalk.

Tracks and File Chunks

In the standard MIDI file specification, there are three file formats that are defined; the SCO2MIDI program produces only format 1, a file that contains one or more simultaneous tracks of a sequence. Following standard MIDI practice, the first track contains only tempo and time signature information, so that all files will contain at least two tracks of data. Tempo and timing data must be included at the beginning of the score file. Following that, data for individual tracks for the entire composition are put together, divided by separator statements (S). Comments may be interspersed anywhere. Data statements may specify any MIDI channel and may be input in any order, since events are sorted into chronological order before the track is written to the file. In the current version of the SCO2MIDI program, there is a limitation of 2300 events per track.

Timing Data

Time is quantized into beats, which can be set to any metronome value between 10 and 238. Since beats are the only method of representing time, measure numbers must be defined by the time signature. The composition begins at beat zero, not one. If the time signature is constant throughout the composition, the starting measure of a beat can be computed by multiplying the top number of the time signature by the measure number (measure 31 in a 3/4 composition thus starts at beat 93). Beats can be defined to any degree of accuracy (three or more decimal points, for example).

Statement Format

Score files must adhere to a strict, easy-to-understand format. Each type of MIDI event has a unique command letter, followed by a MIDI channel (1-16) and an event time expressed in beats. Notes have both a starting time (the event time) and a duration, thus obviating the necessity of thinking in terms of Note On and Note Off messages. Comments may be included anywhere in the file. The metronome mark and time signature are set by T statements.

Events may be specified in any order, except for the fact that the first item in both the file and the track should be a comment and the tempo and time signature data must be specified before any MIDI note data occur. Items are sorted into chronological order according to their event times. Values that do not change on subsequent items repeat or "carry" from the previous item, making it necessary to specify values only when they change.

Each line in the score file specifies a command or operation code (Op Code), followed by data values. Op Codes may be specified in upper of lower case (although the MIDI2SCO program produces lower case). All types of MIDI events as well as some others are included. Table 1 shows the list of commands, their meanings, and the data required.

Except for Comments, all commands have a specific format that must be adhered to. Each line has up to seven fields, and each field must be specified within the columns shown in Table 2. Failure to do so may cause characters to be lost in one field or to be combined with data in other fields. Data can occur anywhere in the field; alignment is not necessary. Table 2 shows the column format for data fields. When typing in large amounts of data, I have found that it is easiest when there is a fixed format like this. Also, the data are aligned for easy proofreading.

Command		Operation			Data Specified
I        	Note On             		Duration, Key (pitch), Velocity
O (*)    	Note Off            		Key (pitch), Release Velocity
A        	After Touch (A/T)   		Key (pitch), Pressure Value
L        	Controller          		Controller Number, Value
P       	Program Change			Program Number
U        	Channel A/T         		Pressure
B        	Pitch Bend          		LSB, MSB
T        	Time Signature/Tempo         	Metronome value, Time Signature
V		Vary Controller			Controller, value 1, value2
S        	Track Separator        		(none)
E        	End of Score        		(none)
M        	Set Middle C Octave 		Octave used for Middle C
N		Track name			Name
C or ;   	Comment             		Any characters

  (*)    Included for compatibility;  see below
 
	Table 1:  Score File Commands

Example Command:  Xccssssssssddddddkkkkvvvv

Column (len)		Shown as	Meaning                                      
  1    	(1)		X          	Command letter (see Table 1)
  2-3   (2)		cc         	Channel number (1-16)
  4-11  (8)		ssssssss   	Event time, in beats
 12-17  (6)  		dddddd     	Duration, in beats (notes only)
 18-21  (4)  		kkkk       	Data value 1 (pitch and octave for notes)
 22-25  (4)  		vvvv       	Data value 2
 26-29  (4)		zzzz		Data value 3

	Table 2:  Statement Format

The first line in the file should be a comment; a title is suggested. Event times and durations are specified in beats, which click at the rate set by the metronome. This enables you to use whole numbers for simple values, and you should never have to convert time values to seconds. Decimal fractional values may be specified in either the starting time or duration fields. They can actually be specified anywhere, except that no fractional data are used except for time values, quantized into "ticks".

After the 29th column on any line, or for any unused field, any data may be typed. This may be useful for numbering notes, indicating measure numbers, or for other purposes. No alphabetic data may be present within the first 29 columns of the lines.

Since items are specified one at a time on successive lines, repeating values separately for each event can be tedious. To avoid this problem, and to decrease the typing necessary to specify a score, the csound carry feature has been implemented. This means that when a blank field is found in any line after the first in a sequence of the same operation, its value is taken or "carries" from the immediately preceding line. (A blank in the first line is taken to be zero.) The carry feature affects all types of data, but it is most useful for channel, velocity, octave, and to a lesser extent, event times and durations.

Input files to the SCO2MIDI program must be stored in ASCII (text) format and must have the extension ".MSC" (“Midi SCore) as part of the name (e.g. PIECE.MSC). The output file will have the same first name with the extension ".MID" (e.g. PIECE.MID). ASCII files can be produced by most word processors, although they must be saved not in their standard format, and care must be taken that the extension is appended properly. The Notepad Editor in Windows and the EDIT program in MS-DOS save all files in ASCII text format.

Individual Commands

1. Note (I): "I" is meant to stand for "instrument", since each MIDI channel controls a separate "instrument" or synthesizer program. (This also bears a historical relationship to the csound input nomenclature.) Notes can be placed in the score in any order; they will later be sorted into chronological order by their starting times. It is usually most convenient to include all the notes for different channels or instruments together; it may also be convenient to order them to make maximum use of the carry feature, in order to minimize typing (for example, putting all the quarter notes together to carry the duration, or all the A-flats to carry the pitch).

Any number of simultaneities may be specified for any channel, but these will not necessarily be playable on the synthesizer unless it has the required number of voices. When too many are played, note stealing will occur just as when you play too many keys. Since it is not possible to strike a key when it is already down, if a note is reattacked before a previous note ends, the duration of the previous note will be shortened accordingly. One pass of the program, ("Checking durations..."), checks all of the notes looking for such note overlapping. Durations will be shortened only if they specify the same key and the same channel.

The key numbers of notes may be specified as 0 to 127, but this is not intended to be used except possibly as an expedient. MIDI keys 0 to 8 are below the range of the piano; the lowest C on the piano is key 12; the lowest C on most MIDI keyboards is 36; middle C is 60.

Since the keys are used to indicate the pitch of notes, the pitch and octave may instead be input themselves. Notes are indicated according to their usual letter names: C, D, E, F, G, A, and B (upper or lower case letters may be used). Sharps are indicated by "#" and flats by "b"; these are placed after the letter names (e.g., C#, Db, etc.). Sorry, but double sharps and flats are not recognized. If there is no accidental on the note, then a blank space must appear after the letter name. To facilitate readability, the four-column field (18-21) should begin with a space; then the letter name, the accidental or blank, and the octave number are typed.

Only a one-digit octave number is recognized. Middle C through B above are in octave 4; from B below middle C down to an octave below middle C is octave 3, etc. This represents what is the most common use of octave designations in current practice. Since this system is in conflict with others used, and since notes above B 9 would have to be specified numerically (these are way off the top end of the piano keyboard anyway), the M command has been included to allow the octave of Middle C to be specified. The only relevant data on this command is the octave number, which is put where the pitch would normally occur. This command affects all note data following the line where it occurs. Additional M commands may be included to change the Middle C designation later in the file.

The carry feature affects both the pitch name and the octave separately. When a series of notes are in the same octave, it needs to be indicated only on the first one. Note velocity is specified merely on a scale of 1 to 127. Velocity zero is used for Note Off in the MIDI specification and is thus disallowed. Since the highest value is a 3-digit number, column 22 should normally be blank; in most cases, 22 and 23 will be blank, and the 2-digit velocity value will occupy columns 24 and 25. If the velocity is blank, which it will often be, then the velocity will be carried from the previous note. However, if the first velocity specified is blank, then the value of 64 will be used. This allows you to get a "mezzo" amplitude without specifying any velocities, and it may be useful for non-velocity sensitive keyboards, which produce a velocity of 64 for all notes.

2. Note Off (O): Since Note messages have a duration specified, they already include a note off indication, and there is really no reason for having Note Offs, but the command is included for compatibility. In fact, note off messages are stored in the MIDI file as note on with velocity zero.

Note Off messages specify only the event time; there is no duration. Key numbers are indicated according to the same method as for Notes On. The MIDI spec defines a "release velocity" as well, but these are always zero.

3. After Touch (A): This type of after touch is referred to as polyphonic key after touch, whereby each key is allowed to change its pressure value during a performance. Unfortunately, some MIDI instruments do not respond to polyphonic after touch but only to channel after touch (see below), which affects all keys simultaneously. Polyphonic after touch is rarely recorded in MIDI performances, since it may lead to huge amounts of data, although it may be used extensively with wind controllers and other such devices.

The data specified for after touch is event time, key number, which is specified in the same manner as for notes, and the pressure value, specified as 0 to 127. All that happens is that the corresponding pressure value is sent to the key at the time indicated. Changes in pressure must be indicated as separate events.

4. Controller (L): Controllers may be used extensively in MIDI performance, even though only a small number of them have been defined. The values specified include the event time, controller number, and value to be sent to the controller. The list of controllers in the MIDI Specification is given in Table 3. Controllers that can vary continuously over the full range of values are given low numbers, and those that accept just “on-off” messages, called switches, are numbered 64 and higher. Not all controllers exist on all synthesizers, and some manufacturers have interpreted these in different ways, because not all of them were originally defined. The use and understanding of controllers is one of the fuzziest aspects of MIDI, which bears a strong keyboard bias. Both of the General MIDI specifications 1.0 and 2.0 have revised and extended the definitions of controllers.

			Controller No.		Assignment
			   0			Unused
			   1			Modulation Wheel (MSB)
			   2			Breath Controller
			   4			Foot Controller
			   5			Portamento Time
			   6			Data Entry Slider
			   7			Channel Volume
			   8			Balance
			  10			Pan
			  64			Sustain (damper) Pedal
			  65			Portamento On/Off
			  66			Sostenuto On/Off
			  67			Soft Pedal On/Off
			  68			Legato footswitch
			  96			Data Increment (+1)
			  97			Data Decrement (-1)

	Table 3:  Controllers defined in the MIDI Specification

5. Program Change (P): Program changes specify that the synthesizer change to a different program at the time indicated. All that is specified is the channel number, event time and the program number, specified as a value from 0 to 127. You must know what the program produces on your synthesizer. While the MIDI Specification allows for synthesizers to have 128 different programs (numbered 0 to 127), not all of them can actually store so many programs; values above the legal limit are either ignored or produce other changes. On the Yamaha DX-7 II, for example, internal voices 1 to 64 are specified as 0 to 63, and cartridge voices 1 to 64 are 64 to 127.

6. Channel After Touch (U): Channel after touch messages affect all keys playing on a particular MIDI channel rather than an individual key. The manner in which they affect the sounds is defined by the program playing, and there is no standard interpretation.

All that is specified for a Channel After Touch message is channel number, event time, and pressure value, specified as 0 to 127.

7. Pitch Bend (B): Pitch Bend was quantized into two bytes by the MIDI Specification because pitch changes are so critical, and the smallest change will produce a perceptible difference (whereas with other characteristics, such as pressure or velocity, even large changes may not be perceptible). I should mention that I have rarely used Pitch Bend, and when I have used it a huge number of messages have been produced in the file.

The data specified for a Pitch Bend command is channel number, event time, and two data bytes, with the least significant byte specified first. How these values affect the synthesizer can only be determined by the program, and many synthesizers allow a range of values that the pitch bend changes can be programmed into.

When pitch bend indications are recorded during a MIDI performance, it is usual that a separate MIDI message is produced each time that the bender changes by a value of 1. Since bender movements are usually rapid, this means that a large number of messages are produced in a short time. Some sequencers even have a method of "thinning out" pitch bend messages, which amount to deleting every other one or some such process. Any number of pitch bend commands can be inserted into a score file with time values changing as fast as you want, but each one of them must be on a separate line. The carry feature is obviously a useful feature for this purpose.

Even with these warnings, however, I am not convinced of the usefulness of specifying bender messages individually, one at a time. I would recommend that users experiment with bender messages or try to insert them manually into the MIDI file, after the program has been used to generate the basic notes, rhythms and controller messages of the piece.

8. Vary Controller (V): Continuous controllers whose values can vary over the full range of MIDI data are very important in live performance. These include foot pedals, the modulation wheel, breath controller, pan, balance, and most important, the channel volume. It is worth noting that, in the original MIDI specification, this was the main volume for the entire keyboard, but it was revised by the General MIDI specification to be the volume for a specific channel. Most changes of dynamics or other varying qualities of the sound must be specified by controller messages.

The V statement includes a starting time, duration, controller number, and two data values. The statement produces a number of controller messages, at equally-spaced time intervals, which begin at the value indicated at the starting time and increase or decrease to produce the last value at the end of the duration. Two important qualifications need to be mentioned: First, in order to produce a smaller number of messages, since the limit of 2300 can messages be a real problem in this situation, new values are produced that differ by two rather than one. Second, although the idea is to vary from the first to last value, the final value is not actually produced; it is ready for a new statement to begin at the ending time.

To produce a crescendo and diminuendo beginning at time 10 and lasting until 12, the following two statements could be used:

	V 1      10     1   7  80 120
	V 1      11     1   7 120  80

The first statement will produce 20 distinct MIDI controller messages starting with 80 at time 10, 82 at time 10.05, 84 at 10.1, ..., and 118 at time 10.95, and the second one will produce another 20 messages, starting from 120 at time 11 and ending at 82 at time 11.95. If you really want to go from 80 to 120 and back to 80, you could either indicate the final value as 78 or include an L statement to set the value of controller 7 to 80 at time 12. For most expressive purposes in MIDI performances dealing with dynamics or timbre change, these differences will not be perceptible.

9. Tempo and Time Signature (T): This command combines both the MIDI tempo and time signature statements into a single command, which means that both parameters must always be specified even if only one of them is being changed. Further, the tempo and time signature commands must occur at the beginning of the file, before the first track of note data, and it must be followed by a separator (S). (In standard MIDI files, the first track contains timing and other text data, but no instrument data.) If more than one tempo and time signature statement occurs, indicating changes through the composition, these must occur in sorted order.

The timing command specifies the event time, metronome mark, numerator and denominator of the time signature, in that order. Data are specified in the same fields as for notes, except that no MIDI channel is specified. For example, the following line:

			T       0    84   3   4

specifies a metronome mark of 84 and a time signature of 3/4 at time zero (the beginning of the piece). If no T command is present, the program assumes default values of a metronome mark of 120 and time signature of 4/4.

Metronome values may be set only to between 10 and 238. The next two fields on the T command, specified in the fields for data bytes 1 and 2, indicate the time signature. Byte 1 is the numerator and byte 2 the denominator.

10. Track Separator (S): In the standard MIDI file specification, all data for separate tracks are put into blocks one after the other. MIDI score files do the same, with data for separate tracks separated by the S command. Time values have the same meaning regardless of the track in which they occur. Since each track has a current limitation of 2300 events, it is necessary to organize larger scores into separate tracks even if they occur successively in the music. If you have a piece with more than this number, you can split the data between two tracks and mix them in the sequencer program. Another possibility is to split the composition into two files, generate them separately, and combine them in the sequencer program.

11. End of Score (E): The E command is simply the last line in the file, replacing the last track separator. No values are specified. It is not even necessary to have an E command, because the program will stop reading the score at the end of file; but E should be included to stop the program from getting a headache looking for the end, and it can also be stuck into the middle of a file somewhere to allow you to test the beginning of the file before running all of the notes, which can take a while to compute.

12. Track Name (N): Track name is the only text event permitted in the program. It is very similar to a comment, except that it puts the text into the MIDI file. After the operation code N, any text data is put into the name. The MIDI file specification recognizes numerous text events, such as copyright notice, text, lyrics, markers, etc. All these other text events are decoded simply as comments by the MIDI2SCO program.

13. Middle C Octave (M): Since different conventions exist regarding the octave placement of Middle C, this commands allows scores to be encoded according to different assumptions. The practical reason for including it is to simplify the occurrence of very low or very high notes (in fact such low keys may not always indicate notes), since the program recognizes only a one-digit octave designation, making it impossible for negative numbers or double digit numbers to be included. The MIDI score file default designation for middle C is octave 4.

The Middle C command specifies only the octave number in the first data field, columns 2-3, where the MIDI channel is normally placed. The command affects all notes after it occurs in the file, even in following tracks, and is not counted as a MIDI event.

14. Comment (; or C): Comments may be included anywhere in the score file, and are recommended to make your score readable and to remind yourself what it typed into it. Profanity is not prohibited and may sometimes be useful. Comments are not counted as MIDI events, and any number may be included in the file.

Example Score Files

The following score file listing shows a C major scale in quarter notes on channel 1. The Timing command specifies a metronome mark of 120 beats per minute at 4/4 time. All velocities are 64. The octave carries for the first seven notes and changes only when C 5 is reached. The channel number and durational values are all carried from the first note.

;  C major scale
t         0   120   4   4
s
i 1       1     1 c 4  64
i         2       d
i         3       e
i         4       f
i         5       g
i         6       a
i         7       b
i         8       c 5
e

The following score listing shows the first two measures of Bach's Two Part Invention in A minor. The different hands are indicated both in different tracks and in different channels. Since the quarter note is the beat, sixteenth notes have a duration of .25. The durational value of 1 in track 2 shows what would be indicated as an eighth note tied to an eighth in the score. There is a quarter-note rest at the end of the top line, which is indicated by the absence of any notes at that time. All velocities are 64.

;  Bach two-part invention in a minor
t       0     132   4   4
s
n right hand
i 1     .25   .25 E 4  64
i       .5        A
i       .75       C 5
i      1          B 4
i      1.25       E
i      1.5        B
i      1.75       D 5
i      2      .5  C
i      2.5        E
i      3          G#4
i      3.5        E 5
i      4      .25 A 4
i      4.25       E
i      4.5        A
i      4.75       C 5
i      5          B 4
i      5.25       E
i      5.5        B
i      5.75       D 5
i      6          C
i      6.5        A 4
s
n left hand
i 2      0    .5  A 2
i       .5   1    A 3
i      1.5    .5  G#
i      2      .25 A
i      2.25       E
i      2.5        A
i      2.75       C 4
i      3          B 3
i      3.25       E
i      3.5        B
i      3.75       D 4
i      4      .5  C
i      4.5        A 4
i      5          G#
i      5.5        E
i      6      .25 A
i      6.25       E
i      6.5        A
i      6.75       C 5
i      7          B 4
i      7.25       E
i      7.5        B
i      7.75       D 4
e

The MIDI2SCO and SCO2MIDI Utilities

The MIDI2SCO utility program converts standard MIDI files into MIDI score format, and it produces several kinds of outputs at the user's option. A listing is always produced to the video display, and an option allows the same information to be produced on the line printer. There is also a file output option, allowing a MIDI score file to be produced. This can then be edited by a word processor are reconverted to a MIDI file by the SCO2MIDI program. The file output option allows two formats: csound or MIDI files. The csound option produces a standard numeric score for the csound program, using pitch designations in the octave point pitch-class form. The MIDI file format produces files in the exact format for input to the SCO2MIDI program. Csound files are given the extension ”SCO”, whereas MIDI score files have “.MSC”.

It is important to note that the video display and line printer listing are slightly different from the MIDI file format. First, the MIDI2SCO program may produce negative octave designations, or octaves of 10 or greater, which may not be usable as input to the SCO2MIDI program. Finally, a maximum of 4800 MIDI events can be decoded in a single track. After this number is reached, subsequent events are merely skipped, and decoding continues with the next track.

Starting times are listed with two decimal places of accuracy. Durations also have two digits after the decimal point, but if the duration is less than .01, then three digits are used. Since duration is a six-column field, this means that durations larger than 999.99 beats will be printed with an error flag.

All comments, track names, and text events occurring in the MIDI file are listed as comments in the MIDI score file. Indeed, all data in the MIDI file will be listed, whether or not these are useful.

Indeed, the MIDI2SCO AND SCO2MIDI programs make it possible to go back and forth from one type of representation to the other with almost no editing. Besides deleting some comments, it should be noted that it will be necessary to edit the tempo and time signature statements at the beginning of the file to specify both values on one line.

MIDI score files are large documents, and generally it is not useful to print them out but to edit them with a word processor and listen carefully to the sequence that is produced. Nevertheless, since composers are trained to work on scores and to think that it is important to get all the careful details and expressive features indicated properly, many will find this process more useful than working with the editing features of sequencer programs.

Free downloads of both programs are available: click here for MIDI2SCO and here for SCO2MIDI. These are both executable programs for the PC that run under the Windows Command Prompt (do not select "Run" when prompted, but select "Save"). They can be put into the same directory as the .MSC and .MID files.